﻿var pageIndex = 1;
var pageSize = 20;
var page_count = 0;

$.ajaxSetup({ url: "AuthorityRoles.aspx", type: "post", dataType: "json" });


function BindRoles() {
    $.ajax({
        data: { method: "RoleList",
            page: pageIndex,
            size: pageSize
        }
        , success: function (json) {

            // 先删除原来的行，否则会多次绑定。
            $("#tbl_RolesList tr").each(function (trindex, tritem) {
                if (trindex != 0)
                    $(tritem).remove();
            });
            // 填充表格
            $("#tbl_RolesList").append("#full_RolesList", json.ListRoles);

            // 分页
            page_count = Math.ceil(json.RowsCount / pageSize);

            PagerInit();

        }
    });

}

function DeleteRole(id) {

    if (confirm("数据被删除后将无法恢复，确定要删除吗？")) {
        $.ajax({
            data: { method: "DelRole",
                Id: id
            }
        , success: function (json) {
            var msg = "";
            if (json.isSuccess == "true") {
                msg = "数据删除成功！"
                BindRoles();
            }
            else {
                msg = "数据删除失败，请重试..."
            }
            alert(msg);
        }
        });
    } 
}

function PageClick(pageclickednumber) {
    $("#pager").pager({ pagenumber: pageclickednumber, pagecount: page_count, buttonClickCallback: PageClick });
    pageIndex = pageclickednumber;
}

function PagerInit() {
    $(document).ready(function () {
        $("#pager").pager({ pagenumber: pageIndex, pagecount: page_count, buttonClickCallback: PageClick });
    });
}

function init() {
    BindRoles();


}
